package com.etime.shycourse.controller.salers;

import com.etime.shy.common.BaseMessage;
import com.etime.shy.common.PojoMessage;
import com.etime.shycourse.pojo.Takeslice;
import com.etime.shycourse.services.salers.interfaces.TakesliceServices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wb
 * @since 2022-05-24
 */
@Api(tags = "后台-提成比例")
@RestController
@RequestMapping("/sys/takeslice")
public class TakesliceController {
    @Autowired
    private TakesliceServices service;

    @ApiOperation("根据id修改系统中统一的提成比例。返回int 成功 =1 失败=0 ")
    @PostMapping("/update")
    public BaseMessage updateById(Takeslice takeslice) {
        BaseMessage msg = new BaseMessage();
        int i = service.updateById(takeslice);
        if (i > 0) {
            msg.setCode(i);
            msg.setMsg("修改成功");
        } else {
            msg.setCode(0);
            msg.setMsg("修改失敗");
        }
        return msg;
    }

    @ApiOperation("查看系统中统一的提成比例")
    @GetMapping("/get")
    public PojoMessage selectByOne() {
        PojoMessage msg = new PojoMessage();
        Takeslice data = service.selectByOne();
        if (data != null) {
            msg.setCode(1);
            msg.setData(data);
        } else {
            msg.setCode(0);
        }
        return msg;
    }
}
